package com.explorati.LeetCode226.invertbinarytree;

/**
 * 226. Invert Binary Tree  反转二叉树：将一个根为节点两侧的数反转
 * 
 *  	 4                     4
 *     /   \			      /   \
 *    2     7    ->      7     2
 *   /  \  /  \           / \     / \
 *  1   3 6  9         9  6   3  1
 * 
 * @author explorati
 *
 */
public class Solution {
	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

	public TreeNode invertTree(TreeNode root) {
		if(root == null){
			return null;
		}
		
		invertTree(root.left);
		invertTree(root.right);
		TreeNode temp = root.left;
		root.left = root.right; 
		root.right = temp;
		return root; 
	}
}
